home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / 80x0393.zip / SB-PROG.TXT < prev    next >
Text File  |  1993-03-30  |  22KB  |  477 lines

  1.  
  2.                       Programming the AdLib/Sound Blaster
  3.                                 FM Music Chips
  4.                            Version 2.0 (24 Feb 1992)
  5.  
  6.                   Copyright (c) 1991, 1992 by Jeffrey S. Lee
  7.  
  8.                                jlee@smylex.uucp
  9.  
  10.  
  11.  
  12.                         Warranty and Copyright Policy
  13.  
  14.      This document is provided on an "as-is" basis, and its author makes
  15.      no warranty or representation, express or implied, with respect to
  16.      its quality performance or fitness for a particular purpose.  In no
  17.      event will the author of this document be liable for direct, indirect,
  18.      special, incidental, or consequential damages arising out of the use
  19.      or inability to use the information contained within.  Use of this
  20.      document is at your own risk.
  21.  
  22.      This file may be used and copied freely so long as the applicable
  23.      copyright notices are retained, and no modifications are made to the
  24.      text of the document.  No money shall be charged for its distribution
  25.      beyond reasonable shipping, handling and duplication costs, nor shall
  26.      proprietary changes be made to this document so that it cannot be
  27.      distributed freely.  This document may not be included in published
  28.      material or commercial packages without the written consent of its
  29.      author.
  30.  
  31.  
  32.  
  33.                                    Overview
  34.  
  35.      Two of the most popular sound cards for the IBM-PC, the AdLib and the
  36.      Sound Blaster, suffer from a real dearth of clear documentation for
  37.      programmers.  AdLib Inc. and Creative Labs, Inc. both sell developers'
  38.      kits for their sound cards, but these are expensive, and (in the case
  39.      of the Sound Blaster developers' kit) can be extremely cryptic.
  40.  
  41.      This document is intended to provide programmers with a FREE source
  42.      of information about the programming of these sound cards.
  43.  
  44.      The information contained in this document is a combination of
  45.      information found in the Sound Blaster Software Developer's Kit, and
  46.      that learned by painful experience.  Some of the information may not
  47.      be valid for AdLib cards; if this is so, I apologize in advance.
  48.  
  49.      Please note that numbers will be given in hexadecimal, unless otherwise
  50.      indicated.  If a number is written out longhand (sixteen instead of 16)
  51.      it is in decimal.
  52.  
  53.  |   Changes from Version 1 of the file will be indicated by the use of change
  54.  |   bars in the left-hand margin.
  55.  
  56.  
  57.  
  58.                          Chapter One - Sound Card I/O
  59.  
  60.      The sound card is programmed by sending data to its internal registers
  61.      via its two I/O ports:
  62.  
  63.              0388 (hex) - Address/Status port  (R/W)
  64.              0389 (hex) - Data port            (W/O)
  65.  
  66.  |   The Sound Blaster Pro is capable of stereo FM music, which is accessed
  67.  |   in exactly the same manner.  Ports 0220 and 0221 (hex) are the address/
  68.  |   data ports for the left speaker, and ports 0222 and 0223 (hex) are the
  69.  |   ports for the right speaker.  Ports 0388 and 0389 (hex) will cause both
  70.  |   speakers to output sound.
  71.  
  72.      The sound card possesses an array of two hundred forty-four registers;
  73.      to write to a particular register, send the register number (01-F5) to
  74.      the address port, and the desired value to the data port.
  75.  
  76.      After writing to the register port, you must wait twelve cycles before
  77.      sending the data; after writing the data, eighty-four cycles must elapse
  78.      before any other sound card operation may be performed.
  79.  
  80.  |   The AdLib manual gives the wait times in microseconds: three point three
  81.  |   (3.3) microseconds for the address, and twenty-three (23) microseconds
  82.  |   for the data.
  83.  |
  84.  |   The most accurate method of producing the delay is to read the register
  85.  |   port six times after writing to the register port, and read the register
  86.  |   port thirty-five times after writing to the data port.
  87.  
  88.      The sound card registers are write-only.
  89.  
  90.      The address port also functions as a sound card status byte.  To
  91.      retrieve the sound card's status, simply read port 388.  The status
  92.      byte has the following structure:
  93.  
  94.               7      6      5      4      3      2      1      0
  95.           +------+------+------+------+------+------+------+------+
  96.           | both | tmr  | tmr  |              unused              |
  97.           | tmrs |  1   |  2   |                                  |
  98.           +------+------+------+------+------+------+------+------+
  99.  
  100.           Bit 7 - set if either timer has expired.
  101.               6 - set if timer 1 has expired.
  102.               5 - set if timer 2 has expired.
  103.  
  104.                        Chapter Two - The Registers
  105.  
  106. The following table shows the function of each register in the sound
  107. card.  Registers will be explained in detail after the table.  Registers
  108. not listed are unused.
  109.  
  110.    Address      Function
  111.    -------      ----------------------------------------------------
  112.      01         Test LSI / Enable waveform control
  113.      02         Timer 1 data
  114.      03         Timer 2 data
  115.      04         Timer control flags
  116.      08         Speech synthesis mode / Keyboard split note select
  117.    20..35       Amp Mod / Vibrato / EG type / Key Scaling / Multiple
  118.    40..55       Key scaling level / Operator output level
  119.    60..75       Attack Rate / Decay Rate
  120.    80..95       Sustain Level / Release Rate
  121.    A0..A8       Frequency (low 8 bits)
  122.    B0..B8       Key On / Octave / Frequency (high 2 bits)
  123.      BD         AM depth / Vibrato depth / Rhythm control
  124.    C0..C8       Feedback strength / Connection type
  125.    E0..F5       Wave Select
  126.  
  127. The groupings of twenty-two registers (20-35, 40-55, etc.) have an odd
  128. order due to the use of two operators for each FM voice.  The following
  129. table shows the offsets within each group of registers for each operator.
  130.  
  131.  
  132.    Channel        1   2   3   4   5   6   7   8   9
  133.    Operator 1    00  01  02  08  09  0A  10  11  12
  134.    Operator 2    03  04  05  0B  0C  0D  13  14  15
  135.  
  136. Thus, the addresses of the attack/decay bytes for channel 3 are 62 for
  137. the first operator, and 65 for the second.  (The address of the second
  138. operator is always the address of the first operator plus three).
  139.  
  140. To further illustrate the relationship, the addresses needed to control
  141. channel 5 are:
  142.  
  143.     29 - Operator 1  AM/VIB/EG/KSR/Multiplier
  144.     2C - Operator 2  AM/VIB/EG/KSR/Multiplier
  145.     49 - Operator 1  KSL/Output Level
  146.     4C - Operator 2  KSL/Output Level
  147.     69 - Operator 1  Attack/Decay
  148.     6C - Operator 2  Attack/Decay
  149.     89 - Operator 1  Sustain/Release
  150.     8C - Operator 2  Sustain/Release
  151.     A4 -             Frequency (low 8 bits)
  152.     B4 -             Key On/Octave/Frequency (high 2 bits)
  153.     C4 -             Feedback/Connection Type
  154.     E9 - Operator 1  Waveform
  155.     EC - Operator 2  Waveform
  156.  
  157.  
  158.  
  159.                        Explanations of Registers
  160.  
  161. Byte 01 - This byte is normally used to test the LSI device.  All bits
  162.           should normally be zero.  Bit 5, if enabled, allows the FM
  163.           chips to control the waveform of each operator.
  164.  
  165.              7     6     5     4     3     2     1     0
  166.           +-----+-----+-----+-----+-----+-----+-----+-----+
  167.           |   unused  | WS  |            unused           |
  168.           +-----+-----+-----+-----+-----+-----+-----+-----+
  169.  
  170.  
  171. Byte 02 - Timer 1 Data.  If Timer 1 is enabled, the value in this
  172.           register will be incremented until it overflows.  Upon
  173.           overflow, the sound card will signal a TIMER interrupt
  174.           (INT 08) and set bits 7 and 6 in its status byte.  The
  175.           value for this timer is incremented every eighty (80)
  176.           microseconds.
  177.  
  178.  
  179. Byte 03 - Timer 2 Data.  If Timer 2 is enabled, the value in this
  180.           register will be incremented until it overflows.  Upon
  181.           overflow, the sound card will signal a TIMER interrupt
  182.           (INT 08) and set bits 7 and 5 in its status byte.  The
  183.           value for this timer is incremented every three hundred
  184.           twenty (320) microseconds.
  185.  
  186.  
  187. Byte 04 - Timer Control Byt